package com.atguigu.srb.core.controller.api;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.pojo.entity.LendReturn;
import com.atguigu.srb.core.service.LendReturnService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 还款记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/api/core/lendReturn")
public class ApiLendReturnController {
    @Autowired
    LendReturnService lendReturnService;
    //http://192.168.1.170/api/core/lendReturn/notifyUrl
    @ApiOperation("还款后hfb回调的接口")
    @PostMapping("notifyUrl")
    public String notifyUrl(HttpServletRequest request){
        return lendReturnService.commitReturnNotifyUrl(request);
    }
    @ApiOperation("还款")
    @GetMapping("/auth/commitReturn/{id}")
    public R commitReturn(@PathVariable("id")String id,
                          @RequestHeader(value = "token",required = false)String token){
        String formStr = lendReturnService.commitReturn(id,token);
        return R.success().data("formStr" , formStr);
    }
    @ApiOperation("查询指定标的的还款计划")
    @GetMapping("/list/{lendId}")
    public R listLendReturns(@PathVariable("lendId")String lendId){
        List<LendReturn> lendReturns = lendReturnService.list(new LambdaQueryWrapper<LendReturn>()
                .eq(LendReturn::getLendId, lendId)
                .orderByAsc(LendReturn::getCurrentPeriod));//使用期数由小到大排序
        return R.success().data("items",lendReturns);
    }
}

